import React from 'react';
import { Button } from 'antd';
import { ITitleType } from '../../../type';
import { titleMap, strategyBenefitOptions } from '../../../dictionary';
import StrategyBenefitDetailModal from '../StrategyBenefitDetailModal';
import StrategyBenefit from '../StrategyBenefit';
import { ExplainTitle } from '../../../components/index';
import styles from './index.less';

interface IProps {
  /**
   * error
   */
  error?: {
    error1?: boolean;
    error2?: boolean;
  };
  /**
   * loading
   */
  loading?: {
    loading1?: boolean;
    loading2?: boolean;
  };
  /**
   * buttonLoading
   */
  buttonLoading?: boolean;
  /**
   * error
   */
  forecastAndSimulateIsError?: boolean;
  /**
   * 数据源
   */
  data?: any;
  /**
   * 重新评估
   */
  resetButIsLoading?: boolean;
  /**
   * 禁止
   */
  disabled?: boolean;
  /**
   * 重新评估
   */
  onReset?: (e: any) => void;
}

const StrategicBenefitEstimation = (props: IProps) => {
  const {
    data,
    onReset,
    error = {
      error1: false,
      error2: false,
    },
    loading,
    forecastAndSimulateIsError = false,
    resetButIsLoading = false,
    disabled = false,
  } = props;
  const _onReset = (e: any) => {
    onReset && onReset(e);
  };

  // 详情
  const onDetail = async (item: ITitleType.AISTRATEGY | ITitleType.CURRENTSTRATEGY) => {
    await StrategyBenefitDetailModal.show({
      data: data[item],
      titleType: item,
      error: forecastAndSimulateIsError
        ? true
        : item === ITitleType.CURRENTSTRATEGY
        ? error?.error1
        : error?.error2,
    });
  };

  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <div className={styles.title}>
          <ExplainTitle
            title={titleMap[ITitleType.STRATEGIC_BENEFIT_ESTIMATION].title}
            hintText={titleMap[ITitleType.STRATEGIC_BENEFIT_ESTIMATION].hintText}
          />
        </div>
        <Button
          className={styles.resetBut}
          disabled={disabled}
          loading={resetButIsLoading}
          onClick={_onReset}
        >
          重新评估
        </Button>
      </div>
      <div className={styles.content}>
        <div className={styles.bottom}>
          {strategyBenefitOptions.map((item) => {
            return (
              <div className={styles.bottomItem} key={item}>
                <StrategyBenefit
                  loading={
                    item === ITitleType.CURRENTSTRATEGY ? loading?.loading1 : loading?.loading2
                  }
                  titleType={item}
                  data={data[item] && !forecastAndSimulateIsError ? data[item] : {}}
                  onDetail={onDetail}
                />
              </div>
            );
          })}
        </div>
      </div>
    </div>
  );
};

export default StrategicBenefitEstimation;
